package com.lanou.dllo.baisibudejie.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.lanou.dllo.baisibudejie.R;

/**
 * Created by dllo on 15/11/9.
 */
public class WebActivity extends Activity {

    private WebView webView;//定义一个用于显示网页的webView

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_web);

        //初始化
        webView = (WebView) findViewById(R.id.webView);

		webView.loadUrl("http://www.baidu.com");

//        String data = "<html><bady><b>测试内容</b></bady></html>";
        //加载网页源码
//		webView.loadData(data, "text/html", "utf-8");
//        webView.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);

        //返回一个设置对象
        WebSettings settings = webView.getSettings();
        //设置能否识别js语言
        settings.setJavaScriptEnabled(true);
        //设置是否支持缩放
        settings.setSupportZoom(true);

        webView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                // TODO Auto-generated method stub
                super.onProgressChanged(view, newProgress);
                Log.i("lanou", "当前网页加载进度：" + newProgress);
            }
        });

        webView.setWebViewClient(new WebViewClient(){

            /**监听接收到错误信息的回调**/
            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                // TODO Auto-generated method stub
                super.onReceivedError(view, errorCode, description, failingUrl);
                Log.i("lanou", errorCode+"  "+description);
            }
        });
    }

}
